/**
 * Vue 过滤器
 */
import Vue from 'vue'

import ctns from '../constants.js'
import util from '../util.js'
//使用样例：{{item | decode('doccate')}} doccate对应constants.js里的变量名
Vue.filter('decode', function(val, codetype) {
    var res = ctns[codetype][val];
    if (typeof(res) == 'undefined') {
        res = '';
    }
    return res;
});

// 调用样例：{{mydate | formatDate("yyyy-MM-dd hh:mm:ss")}}
Vue.filter('formatDate', function(val, fmt) {
    if(val=='' || val ==null){
        return '';
    }
    //return val;
    //return new Date(val);
    //return Object.prototype.toString.call(val) === "[object String]";
    if (Object.prototype.toString.call(val) === "[object String]") {
        let date = new Date(val.replace(/-/g, '/'));
        console.log(date);
        //return date;
        return util.formatDate(date, fmt);
    } else {

        return util.formatDate(val, fmt);
    }
});

